package com.example.protobufdemo;

import java.util.ArrayList;
import java.util.List;

import com.example.protobufdemo.MainADInfoBean.MainADInfoInterface;
import com.example.protobufdemo.MainADInfoBean.MainADInfoSingle;

import proto.ADTest;
import proto.ADTest.ADInfo;
import proto.ADTest.LoginInfoRes;
import android.R.integer;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class ThirdActivity extends Activity{

	private LoginInfoRes loginInfoRes;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		
		//添加测试数据
		addTestPro();
		
		//保存测试数据
		int mainADNum = loginInfoRes.getAdNum();
		for (int i = 0; i < mainADNum; i++) {
			ADInfo mainAdInfo = loginInfoRes.getAdInfoList(i);
			
			int _mainADIndex = mainAdInfo.getAdIndex();
			String _mainADPicUrl = mainAdInfo.getAdPicUrl();
			String _mainADApkUrl = mainAdInfo.getAdApkUrl();
			
			//保存数据
			MainADInfoBean.getMainADInfoBean().addMainADInfo(_mainADIndex, _mainADPicUrl, _mainADApkUrl);
		}
		
		
		
		//取出数据使用
		MainADInfoBean.getMainADInfoBean().getMainADInfo(new MainADInfoInterface() {
			
			@Override
			public void receiverMainADInfo(Object object) {
				// TODO Auto-generated method stub
				if (object instanceof MainADInfoSingle) {
					MainADInfoSingle mainADSingle = (MainADInfoSingle) object;
					
					int _mainADIndex = mainADSingle.get_mainADIndex();
					String _mainADPic = mainADSingle.get_mainADPicUrl();
					String _mainADApk = mainADSingle.get_mainADApkUrl();
					
					Log.d("ThirdRECEIVER", "adindex:"+_mainADIndex+",adPic:"+_mainADPic+",adApk:"+_mainADApk);
					
				}
				
				
				
				
			}
		});
		
		
		
		
		
		
	}
	
	
	
	
		//测试数据
		private void addTestPro(){
		
			ADTest.LoginInfoRes.Builder builder = ADTest.LoginInfoRes.newBuilder();
			builder.setAdNum(3);
			
			List<ADInfo> adInfoList = new ArrayList<>();
			for (int i = 0; i < 3; i++) {
				ADInfo.Builder adBuilder = ADInfo.newBuilder();
				adBuilder.setAdIndex(i);
				adBuilder.setAdPicUrl("picUrl:"+i);
				adBuilder.setAdApkUrl("apkUrl:"+i);
				
				ADInfo adinfo = adBuilder.build();
				adInfoList.add(i, adinfo);
			}
			builder.addAllAdInfoList(adInfoList);
			
			loginInfoRes = builder.build();
			
		}
}
